--
-- DESCRIPTION
--
-- @COMPANY **
-- @AUTHOR **
-- @DATE ${date} ${time}
--

---@type BP_Sword_C
local M = UnLua.Class()
local BP_SharkClass = UE.UClass.Load("/ActionPlatformer/Blueprints/Characters/Shark/BP_Shark.BP_Shark_C")

-- function M:Initialize(Initializer)
-- end

-- function M:UserConstructionScript()
-- end

function M:ReceiveBeginPlay()
    self.Box.OnComponentHit:Add(self, self.OnComponentHit_Box)
    self.Box.OnComponentBeginOverlap:Add(self, self.OnComponentBeginOverlap_Box)
    self.ProjectileMovement:SetActive(true, true)
end

-- function M:ReceiveEndPlay()
-- end

-- function M:ReceiveTick(DeltaSeconds)
-- end

-- function M:ReceiveAnyDamage(Damage, DamageType, InstigatedBy, DamageCauser)
-- end

-- function M:ReceiveActorBeginOverlap(OtherActor)
-- end

-- function M:ReceiveActorEndOverlap(OtherActor)
-- end

--- 碰撞
---@param HitComponent UPrimitiveComponent
---@param OtherActor AActor
---@param OtherComp UPrimitiveComponent
---@param NormalImpulse FVector
---@param Hit FHitResult
function M:OnComponentHit_Box(HitComponent, OtherActor, OtherComp, NormalImpulse, Hit)
    self.SwordFlipbook:SetFlipbook(self.EmbeddedSequence)
    self.SwordFlipbook:SetLooping(false)
    self.SwordFlipbook:K2_SetRelativeLocation(UE.FVector(-32, 0, 0), false, nil, false)
    self.Box:SetCollisionObjectType(UE.ECollisionChannel.OneWayPlatform)
end

--- 重叠
---@param OverlappedComponent UPrimitiveComponent
---@param OtherActor AActor
---@param OtherComp UPrimitiveComponent
---@param OtherBodyIndex integer
---@param bFromSweep boolean
---@param SweepResult FHitResult
function M:OnComponentBeginOverlap_Box(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult)
    local Shark = OtherActor:Cast(BP_SharkClass)
    if Shark then
        --- 伤害感官触发
        UE.UAISense_Damage.ReportDamageEvent(self, Shark, self:GetOwner(), 10, self:GetOwner():K2_GetActorLocation(), SweepResult.ImpactPoint)
        Shark:ReceiveAttack(15)
        self:K2_DestroyActor()
    end
end

--- 设置与Pawn发生碰撞
function M:SetPawnCollisionBlock()
    self.Box:SetCollisionResponseToChannel(UE.ECollisionChannel.ECC_Pawn, UE.ECollisionResponse.ECR_Block)
end

return M
